package com.zhida.smartcontrol.pop;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.base.BasePopWindow;
import com.jay.tools.recycler.OnItemClick;
import com.jay.tools.recycler.decoration.RecyclerViewItemDecoration;
import com.jay.tools.utils.DimenUtils;
import com.jay.tools.utils.ResUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.Const;
import com.zhida.smartcontrol.pop.adapter.DeviceClassifyAdapter;
import com.zhida.smartcontrol.common.bean.DeviceClassifyBean;

import java.util.ArrayList;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/12/2 002 10:47
 * description: 选择设备类型
 */
public class DeviceClassifyPop extends BasePopWindow {
    private RecyclerView mRView;
    private DeviceClassifyAdapter mAdapter;
    private int mType;

    public DeviceClassifyPop(Context context, int type) {
        super(context);
        this.mType = type;
        initAdapter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.pop_layout_recycler;
    }

    @Override
    protected void initViews(View v) {
        mRView = v.findViewById(R.id.recycler_view);
        mRView.setLayoutManager(new LinearLayoutManager(mContext));
        mRView.addItemDecoration(new RecyclerViewItemDecoration.Builder(mContext)
                .thickness(DimenUtils.dp2px(mContext, 0.48f))
                .color(ResUtil.getColor(mContext, R.color.c_EEEEEE))
                .create());
    }

    @Override
    protected void initData() {
        mAdapter = new DeviceClassifyAdapter(null);
        mAdapter.bindToRecyclerView(mRView);
        setWidth(DimenUtils.dp2px(mContext, 140));
    }

    private void initAdapter() {
        List<DeviceClassifyBean> beanList = new ArrayList<>();
        if (mType == Const.O_ALL) {
            beanList.add(new DeviceClassifyBean("0", "智能控制器"));
            beanList.add(new DeviceClassifyBean("1", "智能开关"));
            beanList.add(new DeviceClassifyBean("2", "电缆防盗报警器"));
            beanList.add(new DeviceClassifyBean("3", "NB 单灯控制器"));
            beanList.add(new DeviceClassifyBean("4", "PLC 单灯控制器"));
            beanList.add(new DeviceClassifyBean("5", "智能控制器(PLC)"));
            beanList.add(new DeviceClassifyBean("6", "NB 双灯控制器"));
            beanList.add(new DeviceClassifyBean("7", "ZigBee 单灯控制器"));
            beanList.add(new DeviceClassifyBean("9", "4G 智能控制器"));
        }
        if (mType == Const.O_SINGLE) {
            beanList.add(new DeviceClassifyBean("3", "NB 单灯控制器"));
            beanList.add(new DeviceClassifyBean("4", "PLC 单灯控制器"));
            beanList.add(new DeviceClassifyBean("7", "ZigBee 单灯控制器"));
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        if (mType == Const.O_DOUBLE) {
            beanList.add(new DeviceClassifyBean("6", "NB 双灯控制器"));
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        if (mType == Const.O_CTRL) {
            beanList.add(new DeviceClassifyBean("0", "智能控制器"));
            beanList.add(new DeviceClassifyBean("1", "智能开关"));
//            beanList.add(new DeviceClassifyBean("5", "智能控制器(PLC)"));
//            beanList.add(new DeviceClassifyBean("9", "4G 智能控制器"));
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        }

        mAdapter.replaceData(beanList);
    }

    @Override
    protected void initEvents() {
        mAdapter.setClickListener(new OnItemClick<DeviceClassifyBean>() {
            @Override
            public void onClick(DeviceClassifyBean info, int tag) {
                if (null != mListener) {
                    mListener.onClick(info, tag);
                }
                dismiss();
            }
        });
    }

    @Override
    protected int setCustomHeight() {
        return DimenUtils.dp2px(mContext, 200);
    }
}
